package com.example.wc.logindemo.postupload;

import android.content.Context;
import android.graphics.Bitmap;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.toolbox.Volley;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;


public class UploadApi {

    /**
     * 上传图片接口
     * @param bitmap 需要上传的图片
     * @param listener 请求回调
     */
    public static void uploadImg(Context context, Bitmap bitmap, String fileName,
                                 Response.Listener<JSONObject> listener,
                                 Response.ErrorListener errorListener){
        List<FormImage> imageList = new ArrayList<FormImage>() ;
        FormImage formImage = new FormImage(bitmap);
        formImage.setFileName(fileName);
        imageList.add(formImage) ;
        Request request = new PostUploadRequest("http://192.168.2.116/user/api/image/upload",
                imageList, listener, errorListener) ;
        Volley.newRequestQueue(context).add(request) ;
    }
}
